package com.ld.control.business.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.control.business.process.mapper.ProcessNodeParamExampleMapper;
import com.ld.control.business.process.model.ProcessNodeParamExampleModel;
import com.ld.control.business.process.service.ProcessNodeParamExampleService;
import com.ld.control.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 任务流程节点参数模板表 服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2024-05-21
 */
@Service
public class ProcessNodeParamExampleServiceImpl extends ServiceImpl<ProcessNodeParamExampleMapper, ProcessNodeParamExampleModel> implements ProcessNodeParamExampleService {

    @Autowired
    private ProcessNodeParamExampleMapper processNodeParamExampleMapper;

    @Autowired
    private JWTUtils jwtUtils;

    @Override
    public Map<String, ProcessNodeParamExampleModel> getProcessNodeParam(Long processNodeExampleId) {
        Map<String, ProcessNodeParamExampleModel> pparamMap = new HashMap<>();
        QueryWrapper<ProcessNodeParamExampleModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ProcessNodeParamExampleModel.PROCESS_NODE_EXAMPLE_ID, processNodeExampleId);
        List<ProcessNodeParamExampleModel> processNodeParamExampleModelList = processNodeParamExampleMapper.selectList(queryWrapper);
        for (ProcessNodeParamExampleModel processNodeParamExampleModel : processNodeParamExampleModelList) {
            pparamMap.put(processNodeParamExampleModel.getName(), processNodeParamExampleModel);
        }
        return pparamMap;
    }

    @Override
    public void update(ProcessNodeParamExampleModel processNodeParamExampleModel) {
        Long currentUserAccountId = jwtUtils.getCurrentUserAccountId();
        processNodeParamExampleModel.setUpdateBy(currentUserAccountId);
        processNodeParamExampleModel.setUpdateTime(new Date());
        processNodeParamExampleMapper.updateById(processNodeParamExampleModel);
    }
}
